-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Fix: Emit tool_called events immediately in streaming runs #1300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Fix: Emit tool_called events immediately in streaming runs #1300
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for sending this. It seems this PR modifies the lines of code also changed by #974, which already looks good to me. @rm-openai can you take a look at #974 first and then can you share what you think about this PR?
@seratch My apologies for the duplicate work. After looking at both, I think this approach might have a couple of advantages:
This should make the UI feel more responsive, and the code change itself is a bit smaller and more contained. Happy to chat about it or defer to the other solution if that's preferred. |
This PR is stale because it has been open for 10 days with no activity. |
Hey @seratch @rm-openai. |
It doesnt. There are merge conflicts that were caused by merging #974. I'll fix them briefly. |
@seratch As previously mentioned, advantages to this implementation are:
|
Summary
Resolves #1282
The Solution
The implementation has been updated to emit the semantic
tool_called
event as soon as the first streaming chunk indicating a tool call is received from the model.The
_run_single_turn_streamed
method now inspects rawResponseOutputItemAddedEvent
events as they arrive. If an event's item is a tool call, a correspondingRunItemStreamEvent(name="tool_called")
is immediately constructed and put on the queue.To avoid sending a duplicate event when the full turn results are processed at the end of the stream, a set of
emitted_tool_call_ids
is maintained for the duration of the turn.The check for whether an event item is a tool call has been refactored. Instead of using a long, hardcoded tuple of types, it now dynamically creates this tuple from the
ToolCallItemTypes
alias.